libname jcr "\\tsclient\ste_sas\isi_jcr2012\SocialScience";
run;
/*SOCIAL SCIENCE*/
proc import datafile="\\tsclient\ste_sas\isi_jcr2012\SocialScience\dati" 
		dbms=xls
		out= dati replace;
run;
/*import */
option mprint;
%macro import;
	data _NULL_;
  		set dati;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n;
data WORK.SocialScience&i    ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "\\tsclient\ste_sas\isi_jcr2012\SocialScience\&&name&i...txt" delimiter = ';' MISSOVER DSD lrecl=32767 firstobs=2 ;
 informat Abbreviated_Journal_Title $20. ;
 informat ISSN $9. ;
 informat _2012__Total_Cites best32. ;
 informat Impact_Factor best32. ;
 informat __Year_Impact_Factor best32. ;
 informat Immediacy_Index best32. ;
 informat _2012__Articles best32. ;
 informat Cited_Half_Life $32. ;
 informat Eigenfactor_Score best32. ;
 informat Article_Influence_Score best32. ;
 informat VAR11 $1. ;
 	format Abbreviated_Journal_Title $20. ;
   	format ISSN $9. ;
   	format _2012__Total_Cites best12. ;
    format Impact_Factor best12. ;
   	format __Year_Impact_Factor best12. ;
    format Immediacy_Index best12. ;
 	format _2012__Articles best12. ;
   	format Cited_Half_Life $12. ;
    format Eigenfactor_Score best12. ;
    format Article_Influence_Score best12. ;
    format VAR11 $1. ;
   		input
              Abbreviated_Journal_Title $
              ISSN $
              _2012__Total_Cites
              Impact_Factor
              __Year_Impact_Factor
              Immediacy_Index
              _2012__Articles
              Cited_Half_Life
              Eigenfactor_Score
              Article_Influence_Score
              VAR11 $
 ;
 if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
 run;
 %end;
%mend;
%import;

%macro format;
data _NULL_;
  		set dati;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n;
data SocialScience&i;
format char_Category $80.;
set SocialScience&i;
char_Cited_Half_Life = put(Cited_Half_Life, 7.);
  drop Cited_Half_Life;
  rename char_Cited_Half_Life = Cited_Half_Life;
	drop VAR11;
	char_Category="&&name&i";
	id_Category="&&ID&i";
run;
%end;
%mend;
%format;
/*append*/
data jcr.SocialScience;
format char_Category $80.;
set SocialScience1 - SocialScience56;
if ISSN='' then delete;
Category=substr(char_Category,10);
drop char_Category;
DB="SS";
run; 

/*ARTS & HUMANITIES*/
proc import datafile="\\tsclient\ste_sas\isi_jcr2012\ArtsHumanities\dati" 
		dbms=xls
		out= dati3 replace;
run;
/*import */option mprint;
%macro import;
	data _NULL_;
  		set dati3;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n;

proc import datafile="\\tsclient\ste_sas\isi_jcr2012\ArtsHumanities\&&name&i...txt" 
		dbms=dlm
		out=AH&i replace;
		delimiter=";";
		run;
 %end;
%mend;
%import;
%macro work;
	data _NULL_;
  		set dati3;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n; 
data AH&i;
set AH&i;
y=substr(ARTS___HUMANITIES_CITATION_INDEX,1,1);
if y='' then delete;
run;
%end;
%mend;
%work;

%macro work2;
data _NULL_;
  		set dati3;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n; 
proc sort data= AH&i;
by y;
run;
data AH&i;
set AH&i;
if (y ne "9" & y ne "8" & y ne "7" & y ne "6" & y ne "5" & y ne "4" & y ne "3" & y ne "2" & y ne "1")  then delete;
run;
%end;
%mend;
%work2;

%macro work3;
data _NULL_;
  		set dati3;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n; 
data AH&i;
set AH&i;
ISSN=scan(ARTS___HUMANITIES_CITATION_INDEX,-1," ");
char_Category="&&name&i";
	id_Category="&&ID&i";
run;
%end;
%mend;
%work3;

/*append*/
data jcr.ArtsHumanities;
format Category $80.;
set AH1 - AH28;
if ISSN='' then delete;
Category=char_Category;
drop char_Category y ARTS___HUMANITIES_CITATION_INDE;
DB="AH";
run; 

data jcr.ArtsHumanities;
set jcr.ArtsHumanities;
c=substr(ISSN,1,1);
if (c ne "9" & c ne "8" & c ne "7" & c ne "6" & c ne "5" & c ne "4" & c ne "3" & c ne "2" & c ne "1" & c ne "0")  then delete;
drop c;
run;

/********************************************************************************************/
/********************************************************************************************/

/*SCIENCE*/
proc import datafile="\\tsclient\ste_sas\isi_jcr2012\Science\dati" 
		dbms=xls
		out= dati2 replace;
run;
/*import */
option mprint;
%macro import;
	data _NULL_;
  		set dati2;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n;
data WORK.Science&i    ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "\\tsclient\ste_sas\isi_jcr2012\Science\&&name&i...txt" delimiter = ';' MISSOVER DSD lrecl=32767 firstobs=2 ;
 informat Abbreviated_Journal_Title $20. ;
 informat ISSN $9. ;
 informat _2012__Total_Cites best32. ;
 informat Impact_Factor best32. ;
 informat __Year_Impact_Factor best32. ;
 informat Immediacy_Index best32. ;
 informat _2012__Articles best32. ;
 informat Cited_Half_Life $32. ;
 informat Eigenfactor_Score best32. ;
 informat Article_Influence_Score best32. ;
 informat VAR11 $1. ;
 	format Abbreviated_Journal_Title $20. ;
   	format ISSN $9. ;
   	format _2012__Total_Cites best12. ;
    format Impact_Factor best12. ;
   	format __Year_Impact_Factor best12. ;
    format Immediacy_Index best12. ;
 	format _2012__Articles best12. ;
   	format Cited_Half_Life $12. ;
    format Eigenfactor_Score best12. ;
    format Article_Influence_Score best12. ;
    format VAR11 $1. ;
   		input
              Abbreviated_Journal_Title $
              ISSN $
              _2012__Total_Cites
              Impact_Factor
              __Year_Impact_Factor
              Immediacy_Index
              _2012__Articles
              Cited_Half_Life
              Eigenfactor_Score
              Article_Influence_Score
              VAR11 $
 ;
 if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
 run;
 %end;
%mend;
%import;

%macro format;
data _NULL_;
  		set dati2;
  		call symput ('n', _N_);
  		call symput (compress('name'||_N_),trim(left(nome)));
		call symput (compress('id'||_N_),ID);
		call symput (compress('DB'||_N_),DB);
 	run; 
%do i = 1 %to &n;
data Science&i;
format char_Category $120.;
set Science&i;
char_Cited_Half_Life = put(Cited_Half_Life, 7.);
  drop Cited_Half_Life;
  rename char_Cited_Half_Life = Cited_Half_Life;
	drop VAR11;
	char_Category="&&name&i";
	id_Category="&&ID&i";
run;
%end;
%mend;
%format;
/*append*/
data jcr.Science;
format char_Category $120.;
set Science1 - Science176;
if ISSN='' then delete;
Category=substr(char_Category,10);
drop char_Category;
DB="S";
run; 

/*Journal Citation Report 2012 csv file*/
data jcr.Jcr2012;
format DB $2.;
set jcr.Science jcr.SocialScience jcr.ArtsHumanities;
run;

data jcr.Jcr2012;
set jcr.Jcr2012;
if ISSN="&" then delete;
if ISSN="****-****" then delete;
run;
/*export*/
proc sort data=jcr.Jcr2012;
by ISSN;
run;

proc export data=jcr.Jcr2012 
			outfile="\\tsclient\ste_sas\isi_jcr2012\Jcr_2012.csv" 
			dbms=dlm; 
   			delimiter=';';
run;


